package com.etrans.web.gps.business.system.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.system.domain.SysUser;
import com.etrans.web.gps.business.system.domain.UserVO;

@Service
public class UserService extends BaseService {

	public List<UserVO> queryAllUsers(HashMap<String, Object> params) {
		return this.selectList("userQuery.queryAllUsers", params);
	}

	public long allUsersCount(HashMap<String, Object> params) {
		return (Long) this.selectOne("userQuery.allUsersCount", params);
	}
	
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,Exception.class })
	public int saveUser(UserVO user) {
		this.insert("userMapper.saveUser", user);
		return user.getId();
	}
	
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,Exception.class })
	public void updateUser(UserVO user) {
		this.update("userMapper.updateUser", user);
	}
	
	public UserVO queryUserByUserId(Integer userId) {
		return (UserVO) this.selectOne("userQuery.queryUserByUserId", userId);
	}

	public List<UserVO> queryByUserName(HashMap<String, Object> params) {
		return this.selectList("userQuery.queryByUserName", params);
	}
	
	public int userNameCount(UserVO user) {
		return this.selectOne("userQuery.userNameCount", user);
	}
	
	public int deleteUser(int userId) {
		return this.delete("userMapper.deleteUser", userId);
	}

	/**
	 * 修改密码
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,Exception.class })
	public int updatePassword(HashMap<String, Object> params) {
		return this.update("userMapper.updatePassword", params);
	}

	public SysUser queryUserByPwd(HashMap<String, Object> params) {
		return this.selectOne("userQuery.queryUserByPwd", params);
	}

	public SysUser queryByLoginName(String login_name) {
		return this.selectOne("userQuery.queryByLoginName", login_name);
	}
}
